package Netzwerkprogrammierung.g4.Sockets;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UDPServerThread extends Thread{
	
	private DatagramSocket serverSocket;
	private DatagramPacket receiveData;
	
	public UDPServerThread(DatagramSocket serverSocket,
			DatagramPacket receiveData) {
		this.serverSocket = serverSocket;
		this.receiveData = receiveData;
	}
	
	@Override
	public void run() {
		
		String sentence = new String(receiveData.getData());
		
		InetAddress IPAdress = receiveData.getAddress();
		
		int port = receiveData.getPort();
		
		String modifiedSentence = sentence.toUpperCase();
		
		byte[] sendData = modifiedSentence.getBytes();
		
		DatagramPacket sendPacket = 
				new DatagramPacket(sendData,sendData.length,IPAdress,port);
		
		try {
			serverSocket.send(sendPacket);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	

}
